package com.cxxx.guns.modular.backend.controller;

import com.cxxx.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cxxx.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cxxx.guns.modular.backend.model.Quickimg;
import com.cxxx.guns.modular.backend.service.IQuickimgService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-10-08 15:10:26
 */
@Controller
@RequestMapping("/quickimg")
public class QuickimgController extends BaseController {

    private String PREFIX = "/quickImg/quickimg/";

    @Autowired
    private IQuickimgService quickimgService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "quickimg.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/quickimg_add")
    public String quickimgAdd() {
        return PREFIX + "quickimg_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/quickimg_update/{quickimgId}")
    public String quickimgUpdate(@PathVariable Integer quickimgId, Model model) {
        Quickimg quickimg = quickimgService.selectById(quickimgId);
        model.addAttribute("item",quickimg);
        LogObjectHolder.me().set(quickimg);
        return PREFIX + "quickimg_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return quickimgService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Quickimg quickimg) {
        quickimgService.insert(quickimg);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer quickimgId) {
        quickimgService.deleteById(quickimgId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Quickimg quickimg) {
        quickimgService.updateById(quickimg);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{quickimgId}")
    @ResponseBody
    public Object detail(@PathVariable("quickimgId") Integer quickimgId) {
        return quickimgService.selectById(quickimgId);
    }
}
